<form lay-filter="skuSelectForm" class="layui-form open-form">
  <div class="open-model" id="skuSelectDiv">
    <div class="open-auto">
      <div class="layui-row lay-query-box">
        <div class="layui-inline">
          <label class="layui-form-label w-auto">物料名称</label>
          <div class="layui-input-inline">
            <input name="skuName" type="text" class="layui-input" />
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label w-auto">物料料号</label>
          <div class="layui-input-inline">
            <input name="skuCode" type="text" class="layui-input" />
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label w-auto">规格码</label>

          <div class="layui-input-inline">
            <input type="text" name="skuSpec" placeholder="请输入规格码" class="layui-input" />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label w-auto">物料类别</label>
          <div class="layui-input-block">
            <div id="productTypeName1" lay-filter="productTypeName"></div>
            <input id="productTypeId1" name="productTypeId" type="hidden" />
            <!-- <select id="productTypeId" name="productTypeId" lay-filter="productTypeId"></select> -->
          </div>
        </div>

        <div class="layui-inline">
          <button class="layui-btn icon-btn color-green" type="button" lay-filter="skuQuery" lay-submit layui-form-keyDownSearch="true">查询</button>
          <button class="layui-btn icon-btn color-white" lay-filter="resets" type="button" lay-submit>重置</button>
        </div>
      </div>
      <table class="layui-table" id="skuSelectTable" lay-filter="skuSelectTable"></table>
      <div class="layui-form-item text-right">
        <button class="layui-btn" type="button" id="skuSelectConfirm">确认选择</button>
      </div>
    </div>
  </div>
</form>

<script>
  layui.use(["layer", "tableTreeDj", "upload", "treetable", "form", "table", "laydate", "admin", "laytpl", "upload", "config"], async function () {
    var $ = layui.jquery;

    var layer = layui.layer;
    var table = layui.table;
    var config = layui.config;
    var form = layui.form;
    var admin = layui.admin;
    var tableTree = layui.tableTreeDj;
    var treetable = layui.treetable;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;
    var upload = layui.upload;
    const nowData = { ...parentData };
    let type='radio'
    if(nowData.type){
      type=nowData.type
    }

    admin.initDataSelectTree(true, "enterprise/product/admin/productType/getAllTreeData", { materialNatureList: [2, 3, 7] }, "productTypeName1", null, "物料类别", "productTypeId");
    table.render({
      id: "skuSelectTable",
      elem: "#skuSelectTable",
      url: config.base + "enterprise/product/admin/productDetailWMS/list",

      page: true,
      where: {
        categoryType: "production",
        ...nowData.where
      },
      cols: [
        [
          { type: type, title: "选择", width: 60 },
          { type: "numbers", title: "序号", align: "center", width: 60 },
          { field: "skuCode", align: "center", title: "物料编码", width: 120 },
          { field: "skuName", align: "center", title: "物料名称", width: 120 },
          { field: "skuSpec", align: "center", title: "规格码", width: 120 },
          { field: "productTypeName", align: "center", title: "物资类别", width: 120 },
          { field: "productCategoryId", align: "center", title: "自定义分类", width: 120 },
          {
            field: "isDeleted",
            align: "center",
            title: "状态",
            width: 120,
            templet: function (d) {
              return d.isDeleted ? "停用" : "正常";
            }
          },
          { field: "createTime", align: "center", title: "创建时间", width: 120 },
          { field: "modifierName", align: "center", title: "创建人", width: 120 }
        ]
      ]
    });

    form.on("submit(skuQuery)", function (data) {
      table.reload("skuSelectTable", {
        where: data.field,
        page: { curr: 1 }
      });
    });
    form.on("submit(resets)", function (data) {
      table.reload("skuSelectTable", {
        where: admin.resetSearch(data.field),
        page: { curr: 1 }
      });
    });
    $("#skuSelectConfirm").click(function () {
      let skuObj = table.checkStatus("skuSelectTable").data[0];
      if (skuObj) {
        childData.skuObj = skuObj;
        layer.close(nowData.zindex);
      } else {
        layer.msg("请选择物料");
      }
    });
  });
</script>
